﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace FamilyTree
{
    public partial class TreeCheck : Form
    {
        public TreeCheck()
        {
            InitializeComponent();
        }

        private void TreeCheck_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            string connString = @"Data Source = PC-20190806MQPW\SQLEXPRESS01; Initial Catalog = 终极电子族谱; User ID = sa; Password = 123456"; //数据库连接
            string id = textBoxID.Text;
            SqlConnection conn = new SqlConnection(connString);
            conn.Open();
            string sql = @"SELECT * FROM tree WHERE id='" + textBoxID.Text + "'";
            SqlCommand cmd = new SqlCommand(sql, conn);
            SqlDataReader dr = cmd.ExecuteReader();
            if (!dr.Read())
            {
                MessageBox.Show(id + "号族谱不存在！");
                return;
            }
            textBox1.Text = dr["name"].ToString();
            textBox2.Text = dr["brief"].ToString();
            textBox3.Text = dr["ruler"].ToString();
            textBox4.Text = dr["maker"].ToString();
            if (textBoxID.Text == "1")
            {
                yeye.Text = "颜付全";
                nainai.Text = "李秋华";
                baba.Text = "颜小平";
                mama.Text = "周梅";
                erzi.Text = "颜杰";
            }else if (textBoxID.Text == "2")
            {
                yeye.Text = "周守贵";
                nainai.Text = "余双萍";
                baba.Text = "周强";
                mama.Text = "王一丹";
                erzi.Text = "周杰伦";
            }
            conn.Close();
        }
    }
}
